package com.example.bbang.controller;

import com.example.bbang.common.CommonResult;
import com.example.bbang.entity.Money;
import com.example.bbang.entity.Order;
import com.example.bbang.entity.User;
import com.example.bbang.mapper.MoneyMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("money")
public class MoneyController {
    @Resource
    MoneyMapper moneyMapper;


    //测试
    @GetMapping("test")
    public String Test(){
        System.out.println("hello");
        return "hello";
    }

    @GetMapping("/qt")
    public CommonResult getElseMoney(String username){
        System.out.println(username);
        return CommonResult.ok(moneyMapper.findElseAll(username)) ;
//        return CommonResult.ok(new User());
    }

    @PostMapping("/update")
    public CommonResult updateUser(Money money){
        moneyMapper.updateById(money);
        System.out.println("money:"+money);
        return CommonResult.ok("success") ;
    }

    @PostMapping("/add")
    public CommonResult addMooney(Money money){
        moneyMapper.save(money);
        return CommonResult.ok("success") ;
    }

    @PostMapping("/updatebyname")
    public CommonResult updateByUsername(@RequestParam String username,@RequestParam Integer x){
        moneyMapper.updateByUsername(username,x);
        System.out.println("username:"+username+"x:"+x);
        return CommonResult.ok("success") ;
    }

    @PostMapping("/updatebyname1")
    public CommonResult updateByUsername1(@RequestParam String username,@RequestParam Integer x){
        moneyMapper.updateByUsername1(username,x);
        System.out.println("username:"+username+"x:"+x);
        return CommonResult.ok("success") ;
    }
}
